<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let obj = {
      name: "xiaoming",
      age: 24,
      sayHello: function (job, hobby) {
        console.log(`我叫${this.name},今年${this.age}岁。我的工作是: ${job}，我的爱好是: ${hobby}。`);
      }
    }
    obj.sayHello('程序员', '看漫画'); // 我叫xiaoming,今年24岁。我的工作是: 程序员，我的爱好是: 看美女。


    let obj1 = {
      name: "lihua",
      age: 30
    }
    let obj2 = {
      name: "guohao",
      age: 18
    }
    Object.prototype.myCall = function () {
      const arr = [...arguments]
      const _this = arr.shift()
      _this.sayHello = this
      _this.sayHello(...arr)
    }
    Object.prototype.myapply = function () {
      const arr = [...arguments]
      if (arr.length > 2) {
        throw Error('参数不对')
      }
      const _this = arr[0]
      const obj = arr[1]
      if (!Array.isArray(obj)) {
        throw Error('is not Array')
      }
      _this.sayHello = this
      _this.sayHello(...obj)
    }
    Object.prototype.mybind = function () {
      const arr = [...arguments]
      const _this = arr.shift()
      _this.sayHello = this
      return () => {
        _this.sayHello(...arr)
      }
    }
    obj.sayHello.myCall(obj1, '程序员', '写代码')
    obj.sayHello.myCall(obj2, '程序员', '写WEB')
    obj.sayHello.myapply(obj2, ['游戏高手', '王者'])
    obj.sayHello.mybind(obj2, '游戏高手', '吃鸡')()
  </script>
</body>

</html>